﻿@{
    ViewBag.Title = "Role ActionModule Management";
}
<br />
<h2>Role ActionModule Management</h2>
<br />
@(Html.Telerik().Grid<string[]>()
    .Name("Grid")
    .DataKeys(keys => keys.Add(c => c))
             .ToolBar(commands =>
             {
                 commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" });
             })
    .Columns(columns =>
    {
        columns.Bound(o => o);
       
        columns.Command(command => { command.Edit().ButtonType(GridButtonType.Image); }).Width(50);
    })
    //.DetailView(ActionModule => ActionModule.ClientTemplate(
    //                Html.Telerik().Grid<Century.Models.Common.ActionModuleItem>()
    //                    .DataKeys(keys => keys.Add(c => c.Id))
    //                    .Name("ActionModuleItem_<#= Id #>")
    //                    .Columns(columns =>
    //                    {
    //                        columns.Bound(o => o.Id);
    //                        columns.Bound(o => o.Name);
    //                        columns.Bound(o => o.DisplayName);
    //                        columns.Bound(o => o.RequiredAdministrator);
    //                        columns.Bound(o => o.RoleHasThisActionModule)
    //                        .ClientTemplate("<input type='checkbox' name='RoleHasThisActionModule' value='<#= Id #>'  <#= RoleHasThisActionModule?'checked':'' #> onchange = 'ChangeRoleActionModule(this)' />");
    //                    })
    //                    .DataBinding(dataBinding => dataBinding.Ajax()
    //                                                    .Select("GetActionModulesForRole", "RoleActionModuleManagement", new { roleId = "<#= Id #>" })
    //                                )
    //                                .Sortable()
    //                                .Filterable()
    //                                .ToHtmlString()
    //            ))
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("GetRoleList", "RoleActionModuleManagement")
            .Insert("InsertRole", "RoleActionModuleManagement")
            //.Update("EditRole", "RoleActionModuleManagement")
    )
    .Groupable()
    .Filterable()
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Sortable(sortable => sortable.OrderBy(order => order.Add(o => o)))
    .Pageable(pagingSetting => pagingSetting.PageSize(20))
    .Resizable(config => { config.Columns(true); })
    .Reorderable(config => { config.Columns(true); })
    .ColumnContextMenu()
)
<script type="text/javascript">
    

    function ChangeRoleActionModule(sender) {
        $.ajax({
            type: "post",
            url: '@Url.Action("ChangeRoleActionModule", "RoleActionModuleManagement")',
            data: { roleId: sender.parentElement.parentElement.parentElement.parentElement.parentElement.id.split('_')[1],
                ActionModuleId: sender.value,
                roleHasThisActionModule: sender.checked
            },
            dataType: "html",
            success: function (msg) {
                alert('Role ActionModule has been changed successfully');
            },
            error: function (msg) {
                alert('Error on changin Role ActionModule');
            }
        });
    }
   
</script>
